<template>
  <div class="sg-drawing">
    <Info :detail="detail" />
    <c-section title="设计区域及面积明细">
      <!-- 十月页面优化START -->
      <DoorTable ref="table" :table-data="tableData" :detail="detail" />
      <!-- 十月页面优化END -->
    </c-section>
    <div class="btn-container">
      <c-button type="primary" @click="saveHandle">保存</c-button>
      <c-button type="primary" @click="submitHandle">提交</c-button>
    </div>
  </div>
</template>
<script>
import Info from './components/Info'
import { getBasicsInfo, postQueryAreaSeries, postPageNew, addOutpicAreaMaintain, postDetailCommit } from '@/api/shopDrawing'
import { otherFiltersItem } from '@/utils'
import DoorTable from './components/DoorTable'
export default {
  name: 'ShopDrawingDetailManagementSGDoorDrawing',
  components: {
    Info,
    DoorTable
  },
  data() {
    return {
      detail: {},
      tableData: []
    }
  },
  computed: {
  },
  created() {
    this.getDetail()
    this.getAreaSeries()
  },
  methods: {
    getDetail() {
      getBasicsInfo(this.$route.query.id).then(res => {
        this.detail = res.data
      })
    },
    queryData() {
      const fr = []
      const p = {}
      p.isReportPic = '1'
      return [fr, p]
    },
    getAreaSeries() {
      const otc = this.$route.query.outpicDetailTaskCode
      postPageNew(this.$route.query.id, otc).then(res => {
        // if (res.data.records.length === 0) {
        //   return postQueryAreaSeries(this.$route.query.id, ...this.queryData())
        // }
        return res
      }).then(res => {
        if (this.detail.detailTaskSchedule === 'A') {
          this.tableData = res.data.records.map(e => {
            e.isProgramOutpic = '1'
            e.isDetailOutpic = '1'
            return e
          })
        } else {
          this.tableData = res.data.records
        }
      })
    },
    // 保存数据
    saveData() {
      return this.$refs.table.validate().then(tabledata => {
        const data = {
          id: this.$route.query.id,
          outpicDetailTaskCode: this.$route.query.outpicDetailTaskCode,
          picBatchCode: this.$route.query.picBatchCode,
          designAreaSeriesDTOList: tabledata
        }
        return addOutpicAreaMaintain(data)
      })
    },
    // 保存
    saveHandle() {
      return this.saveData().then(res => {
        this.$message.success('保存成功！')
        this.$store.dispatch('views/goFirst')
      })
    },
    submitHandle() {
      return this.saveData().then(res => {
        return postDetailCommit({
          id: this.$route.query.id,
          outpicDetailTaskCode: this.$route.query.outpicDetailTaskCode,
          picBatchCode: this.$route.query.picBatchCode
        })
      }).then(res => {
        this.$message.success('操作成功！')
        this.$store.dispatch('views/goFirst')
        // this.$router.push({ name: 'ShopDrawingDetailManagementCategory', query: { ...this.$route.query }})
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.sg-drawing{
  padding-top: 12px;
  & /deep/ .el-table__row{
    background-color: #fff !important;
  }
  & /deep/ .hover-row{
    background-color: #fff !important;
  }
  & /deep/ td{
    background-color: #fff !important;
  }
}
</style>
